﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Aluetjen.EmailService.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MailMessage = Aluetjen.EMailService.Contract.MailMessage;

namespace Aluetjen.EmailService.Agent.SystemTests
{
    [TestClass]
    public class EmailServiceTests
    {
        [TestMethod]
        public void Send_Default()
        {
            var service = new EmailClient();
            var message = new MailMessage("systest@luetjen.ie", "admin@luetjen.ie", "Whoop!", "This is coming through the WCF service.");

            service.Send(message);
        }

        [TestMethod]
        public void Send_BasicHttp()
        {
            var service = new EmailClient();
            var message = new MailMessage("systest@luetjen.ie", "admin@luetjen.ie", "Whoop!", "This is coming through the WCF service.");

            service.Send(message);
        }

        [TestMethod]
        public void Send_10000()
        {
            var watch = new Stopwatch();
            watch.Start();

            var taskList = new List<Task>();

            for (int j = 0; j < 8; j++)
            {
                var task = new Task(() =>
                                        {
                                            var service = new EmailClient();

                                            for (int i = 0; i < 100000; i++)
                                            {
                                                var message = new MailMessage("systest@luetjen.ie", "admin@luetjen.ie",
                                                                              "Whoop!",
                                                                              "This is coming through the WCF service.");

                                                service.Send(message);
                                            }
                                        });

                task.Start();

                taskList.Add(task);
            }

            Task.WaitAll(taskList.ToArray());

            watch.Stop();

            Console.WriteLine(watch.Elapsed);
        }
    }
}
